#include <iostream>

using namespace std;

const int N = int(1e5 + 10);

int q[N];
int n;

void init(int n)
{
    for (int i = 1; i <= n; i++)
        q[i] = i;
}

int find(int x) // 寻找树根, 顺便压缩路径
{
    if (q[x] != x) q[x] = find(q[x]);
    return q[x];
}

bool query(int a, int b)
{
    return find(a) == find(b);
}

void merge(int a, int b)
{
    int i = find(a);
    int j = find(b);
    q[j] = i;
}

int main(void)
{
    int m, a, b;
    char mode[2];
    scanf("%d%d", &n, &m);
    init(n);
    while (m--)
    {
        scanf("%s%d%d", mode, &a, &b);
        if (mode[0] == 'M') merge(a, b);
        else if (mode[0] == 'Q') 
            printf("%s\n", query(a, b) ? "Yes" : "No");
    }
}